package com.spx.chapter05.source;

import com.spx.util.KafkaUtil;
import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;

import java.util.Properties;

/**
 * create by undeRdoG on  2022-04-29  14:52
 * 凡心所向，素履以往，生如逆旅，一苇以航。
 */
public class KafkaSourceTest {


    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        Properties properties = KafkaUtil.getKafkaCunsumerProperties("hadoop102:9092", "clicks");


        // 从kafka中读取数据， 添加 flink-kafka-consumer
        DataStreamSource<String> kafkaStream = env.addSource(new FlinkKafkaConsumer<>(
                "clicks",
                new SimpleStringSchema(),
                properties
        ));

        kafkaStream.print("kafkaStream");

        env.execute();
    }
}
